﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;

namespace SPThumbnailExtender.Interne
{
    internal class ThumbnailDWG : ThumbnailBase
    {
        public ThumbnailDWG(Uri uri):base (uri)
        {
            this.Width = 640;
            this.Height = 480;
        }
        public ThumbnailDWG(Uri uri, int Width, int Height)
            : base(uri, Width, Height)
        { }
        public override System.Drawing.Bitmap GenerateThumbnail()
        {
            return GenerateThumbnail(0);
        }

        public override System.Drawing.Bitmap GenerateThumbnail(int Page)
        {
            string strPathPNG = Helper.GetSourceFilename(this.FileUri.AbsoluteUri, this.Width, this.Height, Page, ".png");
            FileInfo file = new FileInfo(strPathPNG);
            if (!file.Directory.Exists)
                file.Directory.Create();
            byte[] byteFile = Helper.ReadToEnd( this.GetFileStream());
            Bitmap bmp = acThumbnailReader.GetThumbnail(byteFile);
            Helper.DeleteThumbnail(this.FileUri, Page);
            Helper.InsertThumbnail(this.FileUri, Page, bmp);
            return bmp;
        }

        public override int GetCount()
        {
            return 1;
        }

        public override void GenerateThumbnails()
        {
            Bitmap bmp=GenerateThumbnail(0);
            Helper.DeleteThumbnail(this.FileUri, 0);
            Helper.InsertThumbnail(this.FileUri, 0, bmp);
        }
    }
}
